package com.itany.controller;


import com.itany.crawler.proxy.MyProxyManager;
import com.itany.service.BookService;
import com.itany.vo.ActionResult;
import com.itany.crawler.Main;
import com.itany.crawler.proxy.MyProxy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/crawler")
public class Crawler {

    @Autowired
    private BookService bookService;

    /**
     * log.add("urls.size :" + urls.size());
     * log.add("proxyIP.size :" + MyProxy.proxys.size());
     * log.add("urls.count :" + urls.count);
     * log.add("currentThreadNum :" + currentThreadNum);
     *
     * @return
     */


    @RequestMapping("/info")
    public ActionResult info() {
        ActionResult result = new ActionResult();
        Map<String, Object> map = new HashMap<>();
        map.put("urls.size :", Main.urls.size() + "");
        map.put("MyProxyManager.size :", MyProxyManager.proxys.size() + "");
        map.put("urls.count :", Main.urls.count + "");
        map.put("currentThreadNum :", Main.currentThreadNum + "");
        map.put("runnable :", Main.runnable + "");
        result.setData(map);

        return result;
    }

    @RequestMapping("/urls")
    public ActionResult urls() {
        ActionResult result = new ActionResult();
        result.setData(Main.urls.urls);
        return result;
    }

    @RequestMapping("/proxyIp")
    public ActionResult proxyIp() {
        ActionResult result = new ActionResult();
        result.setData(MyProxy.proxys);
        return result;
    }

    @RequestMapping("/shutdown")
    public ActionResult shutdown() {
        ActionResult result = new ActionResult();
        Main.runnable = false;
        result.setMsg("开始关闭且保存");
        return result;
    }

}
